﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RefOffPDA
{
    /*
     * Class: SubOn
     * 
     * Use: Form displayed when user chooses to start a substitution, where
     *      the player leaving the pitch is identified
     *      
     * Author: Mike Skaife, mcs3@aber.ac.uk
     */      
    public partial class SubOff : Form
    {
        //The current Match object
        Match theMatch;

        //Variable used to indicate if the home or away team is
        //making the substitution
        String homeOrAway;

        //Variables to indicate the id and name of the player leaving the pitch
        int player_id;
        String text;

        public SubOff(Match match, String homeAway)
        {
            InitializeComponent();
            theMatch = match;
            homeOrAway = homeAway;
        }

        //This method displays the SubOn form for the team carrying out
        //the substitution
        private void subPlayer()
        {
            //If the home team is involved, display their 'subs bench'
            if (homeOrAway.Equals("home"))
            {
                theMatch.homeSubOn.Visible = true;
                this.Visible = false;
            }
            //If the away team is involved display their 'subs bench'
            else
            {
                theMatch.awaySubOn.Visible = true;
                this.Visible = false;
            }
        }

        //This method is run when the first player button is clicked
        private void SubOffPlayer1Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer1Btn.Tag.ToString());
            text = this.SubOffPlayer1Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer1Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer1Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer1Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer1Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer1Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer1Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer1Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer1Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();          
        }

        //This method is run when the second player button is clicked
        private void SubOffPlayer2Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer2Btn.Tag.ToString());
            text = this.SubOffPlayer2Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer2Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer2Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer2Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer2Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer2Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer2Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer2Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer2Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the third player button is clicked
        private void SubOffPlayer3Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer3Btn.Tag.ToString());
            text = this.SubOffPlayer3Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer3Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer3Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer3Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer3Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer3Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer3Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer3Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer3Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the fourth player button is clicked
        private void SubOffPlayer4Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer4Btn.Tag.ToString());
            text = this.SubOffPlayer4Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer4Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer4Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer4Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer4Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer4Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer4Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer4Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer4Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the fifth player button is clicked
        private void SubOffPlayer5Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer5Btn.Tag.ToString());
            text = this.SubOffPlayer5Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer5Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer5Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer5Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer5Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer5Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer5Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer5Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer5Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the sixth player button is clicked
        private void SubOffPlayer6Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer6Btn.Tag.ToString());
            text = this.SubOffPlayer6Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer6Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer6Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer6Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer6Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer6Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer6Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer6Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer6Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the seventh player button is clicked
        private void SubOffPlayer7Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer7Btn.Tag.ToString());
            text = this.SubOffPlayer7Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer7Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer7Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer7Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer7Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer7Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer7Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer7Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer7Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the eighth player button is clicked
        private void SubOffPlayer8Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer8Btn.Tag.ToString());
            text = this.SubOffPlayer8Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer8Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer8Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer8Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer8Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer8Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer8Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer8Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer8Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the ninth player button is clicked
        private void SubOffPlayer9Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer9Btn.Tag.ToString());
            text = this.SubOffPlayer9Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer9Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer9Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer9Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer9Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer9Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer9Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer9Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer9Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the tenth player button is clicked
        private void SubOffPlayer10Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer10Btn.Tag.ToString());
            text = this.SubOffPlayer10Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer10Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer10Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer10Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer10Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer10Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer10Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer10Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer10Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }

        //This method is run when the eleventh player button is clicked
        private void SubOffPlayer11Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id and name of the player being subbed off
            player_id = Int32.Parse(this.SubOffPlayer11Btn.Tag.ToString());
            text = this.SubOffPlayer11Btn.Text;

            //This code runs if the home team is making the substitution
            if (homeOrAway.Equals("home"))
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.homeSubOn.subOffButton = theMatch.homeSubOff.SubOffPlayer11Btn;
                theMatch.homeSubOn.sendOffButton = theMatch.homeSendOff.SendOffPlayer11Btn;
                theMatch.homeSubOn.cautionButton = theMatch.homeCaution.CautionPlayer11Btn;
                theMatch.homeSubOn.goalButton = theMatch.homeGoal.GoalPlayer11Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.homeSubOn.playerOff_id = player_id;
                theMatch.homeSubOn.playerOff_text = text;
            }
            //This code runs when the away team is making the substitution
            else
            {
                //Get hold of the relevant buttons for the player leaving the pitch
                //and assigns them to variables in the SubOn screen, so they can
                //be updated when the substitution is completed
                theMatch.awaySubOn.subOffButton = theMatch.awaySubOff.SubOffPlayer11Btn;
                theMatch.awaySubOn.sendOffButton = theMatch.awaySendOff.SendOffPlayer11Btn;
                theMatch.awaySubOn.cautionButton = theMatch.awayCaution.CautionPlayer11Btn;
                theMatch.awaySubOn.goalButton = theMatch.awayGoal.GoalPlayer11Btn;

                //Set varialbles in SubOn screen to indicate that this player is
                //the one being subbed off
                theMatch.awaySubOn.playerOff_id = player_id;
                theMatch.awaySubOn.playerOff_text = text;
            }

            //Display the 'subs bench' so the substitution can be completed
            subPlayer();
        }


        //This code is run when the 'Cancel' button is clicked
        private void CancelButton_Click(object sender, EventArgs e)
        {
            //Close this form to display the main Match screen
            this.Visible = false;
        }
    }
}